public class Offer26 {
    public boolean isSubStructure(TreeNode A, TreeNode B) {
        boolean result = false;
        if (A!=null&&B!=null){
            if (A.val==B.val){
                result = hasB(A,B);
            }
            if (!result){
                result = isSubStructure(A.left,B);
            }
            if (!result){
                result = isSubStructure(A.right,B);
            }
        }
        return result;
    }
    public boolean hasB(TreeNode A, TreeNode B){
        if (B==null){
            return true;
        }
        if (A==null){
            return false;
        }
        if (A.val!=B.val){
            return false;
        }
        return hasB(A.left,B.left)&&hasB(A.right,B.right);
    }
}
